<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>OA办公管理系统-友情链接</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="pragma" content="no-cache"/>
    <meta http-equiv="cache-control" content="no-cache"/>
    <meta http-equiv="expires" content="0"/>
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"/>
    <meta http-equiv="description" content="This is my page"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/bootstrap/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/easyUI/easyui.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/publicStyle.css"/><!--分页样式  -->
</head>
<body style="overflow: hidden; width: 98%; height: 100%;">
<!-- 工具按钮区 -->
<form class="form-horizontal" action="" method="post" style="padding-left: 5px;">
    <table class="table-condensed">
        <tbody>
        <tr>
            <td>
                <a id="addlinksUrl" class="btn btn-success operas"><span class="glyphicon glyphicon-plus"></span>&nbsp;添加</a>
            </td>
        </tr>
        </tbody>
    </table>
</form>
<div class="panel panel-primary" style="padding-left: 5px;">
    <div class="panel-heading" style="background-color: #11a9e2;">
        <label>友情链接列表</label>
    </div>
    <div class="panel-body">
        <table class="table table-bordered table-hover" style="margin-bottom: 0;">
            <thead>
            <tr style="font-size: 12px;" align="center">
                <th style="text-align: center;">名称</th>
                <th style="text-align: center;">博客链接</th>
                <th style="text-align: center;">联系方式</th>
                <th style="text-align: center;">备注</th>
                <th style="text-align: center;">操作</th>
            </tr>
            </thead>
            <tbody id="data_info">

            </tbody>
        </table>

    </div>
    <!--分页条-->
    <div class="pager" id="pager"></div>
</div>

<div id="divDialog">
    <!-- 放置一个添加用户的界面  -->
    <iframe id="iframe" frameborder="0" style="width: 100%;height: 100%;"></iframe>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/jquery/jquery.min.js"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/resources/jquery/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.myPagination.js"></script><!--分页  -->
<!-- 导入bootStrap的库 -->
<script type="text/javascript"
        src="${pageContext.request.contextPath}/resources/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/easyUI/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/easyUI/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/plugins/layer/2.4/layer.js"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/resources/plugins/layer/2.4/LayConstant.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
       selLinksList(1);
    });


    //分页查询用户列表
    var pageSize = 5;
    function selLinksList(pageNo) {
        var nickname = $("#nickname").val();
        var phone = $("#phone").val();
        var params = {"pageNo": pageNo, "pageSize": pageSize,"nickname":nickname,"phone":phone};
        var obj = $("#data_info");
        obj.empty();
        $.ajax({
            url: '${pageContext.request.contextPath}/friendlinks/selLinksList.jspx',
            data: params,
            type: 'post',
            dataType: 'json',
            success: function (data) {
                if (data.code == 0) {
                    var content = data.content[0].info, code = "";
                    var pageCount = data.content[0].pagetotal;//总页数
                    if (content.length < 1) {
                        layer.msg("暂无数据", {icon: 5, time: LayUIConstant.TIP_TIME});
                    } else {
                        for (var i = 0; i < content.length; i++) {
                            var linksId = content[i].sysid;
                            code += '<tr id="links_' + i + '" align="center" style="cursor:pointer;">' +
                                '<td>' + content[i].nickname + '</td>' +
                                '<td>' + content[i].weburl + '</td>' +
                                '<td>' + content[i].phone + '</td>' +
                                '<td>' + content[i].remark + '</td>' +
                                '<td>' +
                                '<a id="updateLinks" class="btn btn-primary"  onclick="updateLinks(\'' + linksId + '\')" style="color: white;">修改</a> ' +
                                '<a id="delLinks" class="btn btn-danger" onclick="delLinks(\'' + linksId + '\')"  style="color: white;">删除</a>' +
                                '</td>' +
                                '</tr>';
                        }
                        obj.append(code);
                        if (pageCount > 0) {
                            //分页
                            $("#pager").myPagination({
                                currPage: pageNo, //初始选择的页数
                                pageCount: pageCount,//总页数
                                pageSize: pageSize //显示多少页
                            });
                        }
                    }
                } else {
                    layer.msg(data.message, {icon: 5, time: LayUIConstant.TIP_TIME});
                }
            },
            error: function () {
                layer.msg("系统错误!", {icon: 5, time: LayUIConstant.TIP_TIME});
            }
        });
    }
    //为添加按钮绑定事件
    $("#addlinksUrl").click(function () {
        $('#divDialog').dialog({
            title: "添加友情链接", // 标题
            cls: "easyui-dialog", // class
            width: 450, // 宽度
            height: 275, // 高度
            maximizable: true, // 最大化
            minimizable: false, // 最小化
            collapsible: true, // 可伸缩
            modal: true, // 模态窗口
            onClose: function () { // 关闭窗口
                selLinksList(1);
               // window.location = "${pageContext.request.contextPath}/friendlinks/selLinksList.jspx?pageNo=1";
            }
        });
        //通过iframe来引入一个添加用户的页面
        $("#iframe").attr("src", "${pageContext.request.contextPath}/friendlinks/showAddLinks.jspx");

    })

    //修改友情链接
    function updateLinks(linksId) {
        $('#divDialog').dialog({
            title: "修改链接", // 标题
            cls: "easyui-dialog", // class
            width: 450, // 宽度
            height: 275, // 高度
            maximizable: true, // 最大化
            minimizable: false, // 最小化
            collapsible: true, // 可伸缩
            modal: true, // 模态窗口
            onClose: function () { // 关闭窗口
                //window.location = "${pageContext.request.contextPath}/friendlinks/selLinksList.jspx";
                selLinksList(1);
            }
        });
        //通过iframe来引入一个修改用户的页面
        $("#iframe").attr("src", "${pageContext.request.contextPath}/friendlinks/showUpdatelinks.jspx?linksId=" + linksId);
    }

  
    //删除链接
    function delLinks(linksId) {
    	if(!confirm("是否删除选中的链接？")){
            return;
        }
        $.ajax({
            url: '${pageContext.request.contextPath}/friendlinks/dellinks.jspx',
            data: {"linksId": linksId},
            type: 'post',
            dataType: 'json',
            success: function (data) {
                if (data.code == 0) {
                    layer.msg(data.message, {icon: 1, time: LayUIConstant.TIP_TIME}, function () {
                        setTimeout(function () {
                            location.reload();
                        },1500)
                    });
                } else {
                    layer.msg(data.message, {icon: 5, time: LayUIConstant.TIP_TIME});
                }
            },
            error: function (data) {
                layer.msg(data.message, {icon: 5, time: LayUIConstant.TIP_TIME});
            }
        });
    }

    //批量删除文章
    function deleteMoreUrl(){

    }
 
    function pageOnClick(page) {
    	selLinksList(page);
    }
    //分页文本框中直接输入时触发： properchange：适用IE9以及以上版本  onchange：IE不适用  两者必须有获取焦点失去焦点后才能触发
    function inputChange() {
        var pageNo = $('#pageInput').val();//文本框中当前页
        selLinksList(pageNo);
    }
</script>


</body>

</html>